
use master

go

if db_id('QLRCP') IS NOT NULL
DROP DATABASE QLRCP
GO
create database QLRCP
GO
USE QLRCP

create table THELOAI
(
MaTheLoai nchar(10) not null,
TenTheLoai nchar(100) not null,

primary key (MaTheLoai)
)
go

create table PHIM
(
MaPhim nchar(10) not null,
TenPhim nchar(100) not null,
MaTheLoai nchar(10) not null, 
ThoiLuong int ,
ThongTin nchar(1000),

primary key (MaPhim)
)

go
create table XUATCHIEU
(
MaXuatChieu nchar(10) not null,
NgayChieu datetime not null,
GiaVeNguoiLon money,
GiaVeTreEm money,
DieuKhoan nchar(1000),
MaPhim nchar(10),
 
 primary key (MaXuatChieu)
 )

go

create table KHACHHANG
(
MaKH nchar(10) not null,
Ten nchar(100) not null,
DiaChi nchar(100) not null,
DienThoai nchar(20) not null,

primary key (MaKH)
)

go

go

create table VE
(
MaVe nchar(10) not null,
MaGhe nchar(10) not null, 
MaXuatChieu nchar(10) not null,
MaHD nchar(10),

primary key (MaVe)
)

go

create table HOADON
(
MaHD nchar(10) not null,
NgayLap datetime not null,
TongTien money,
maKH nchar(10) not null, 
TinhTrang nchar(20) not null,

primary key (MaHD)
)

GO

create table GHE
(
MaGhe nchar(10) not null,
SoGhe int not null,

primary key (MaGhe)
)


ALTER TABLE PHIM
ADD CONSTRAINT FK_PHIM_THELOAI
FOREIGN KEY (MaTheLoai)
REFERENCES THELOAI(MaTheLoai)

ALTER TABLE XUATCHIEU
ADD CONSTRAINT FK_XUATCHIEU_PHIM
FOREIGN KEY (MaPhim)
REFERENCES PHIM(MaPhim)



ALTER TABLE VE
ADD CONSTRAINT FK_Ve_SuatChieu 
FOREIGN KEY (MaXuatChieu)
REFERENCES XUATCHIEU (MaXuatChieu),

CONSTRAINT FK_Ve_hoadon
FOREIGN KEY (MaHD)
REFERENCES hoadon(Mahd),

CONSTRAINT FK_Ve_GHE
FOREIGN KEY (MaGhe)
REFERENCES GHE(MaGhe)


ALTER TABLE hoadon
ADD CONSTRAINT FK_hoadon_khachhang 
FOREIGN KEY (makH)
REFERENCES khachhang (MaKH)


